﻿#Region "Copyright/License"

'  Copyright (C) 2011, 2012, 2013 Paycircuit.com, Thinking Spot, Ed Chavez
'  http://goo.gl/jty8r
' 
'  Licensed under the Apache License, Version 2.0 (the "License");
'  you may not use this file except in compliance with the License.
'  You may obtain a copy of the License at
' 
'       http://www.apache.org/licenses/LICENSE-2.0
' 
'  Unless required by applicable law or agreed to in writing, software
'  distributed under the License is distributed on an "AS IS" BASIS,
'  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
'  See the License for the specific language governing permissions and
'  limitations under the License.

#End Region


Imports System.Runtime.Serialization
Imports System.ComponentModel.DataAnnotations


Namespace google.iap

    <DataContract()>
    Public MustInherit Class SubscriptionPaymentObject

        Private _currencyCode As String = "USD"
        Private _price As String = "0.00"

        ''' <summary>
        ''' Required. The purchase price of the item, with up to 2 decimal places.         
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks>Google will reject value exceeding 2 decimal places.</remarks>
        <Required()>
        <DataMember(EmitDefaultvalue:=False, Order:=1)>
        Public Overridable Property price() As String
            Get
                Return _price
            End Get
            Set(value As String)
                'NOTE: Pending official clarification.
                '   Currently Google sandbox allows 0 value for itemPrice.
                '   While it would be odd to allow 0 value payments, allow 0 value to match official Google spec/current behavior.
                If Not String.IsNullOrEmpty(value) AndAlso IsNumeric(value) AndAlso CDec(value) >= 0 Then
                    _price = value
                Else
                    Throw New ArgumentOutOfRangeException("SubscriptionPaymentObject price", "Recurrent item price is required.")
                End If
            End Set
        End Property

        ''' <summary>
        ''' Required. A 3-character currency code that defines the billing currency. Currently supported currency codes: USD, EUR, CAD, GBP, AUD, HKD, JPY, DKK, NOK, SEK, CHF, NZD, SGD
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        <Required()>
        <StringLength(3, ErrorMessage:="Maximum of 3 characters")>
        <DataMember(EmitDefaultvalue:=False, Order:=1)>
        Public Overridable Property currencyCode() As String
            Get
                Return _currencyCode
            End Get
            Set(value As String)
                If Not String.IsNullOrEmpty(value) AndAlso value.Length <= 3 Then
                    _currencyCode = value
                Else
                    Throw New ArgumentOutOfRangeException("SubscriptionPaymentObject currencyCode", "Required. Maximimum of 3 characters")
                End If
            End Set
        End Property

        Public Sub New()
        End Sub

    End Class

End Namespace
